package com.j1903.contorller;
import com.j1903.annotation.PassJwt;
import com.j1903.bean.Lunbo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.j1903.util.JsonResult;
import javax.annotation.Resource;
import com.j1903.service.LunboService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fjj
 * @since 2021-12-16
 */
@RestController
@RequestMapping("/lunbo")
@Slf4j
@CrossOrigin
public class LunboController {
    @Resource
    private LunboService lunboService;
    @RequestMapping("/add")
    public JsonResult add(@RequestBody Lunbo obj){
        lunboService.save(obj);
        return new JsonResult(200,"添加成功",
                obj.getId());
    }
    @RequestMapping("/upd")
    public JsonResult upd(@RequestBody Lunbo obj){
        Boolean rs=lunboService.saveOrUpdate(obj);
        if(rs){
            return new JsonResult(200,"更新成功");
        }
        else{
            return new JsonResult(500,"更新失败");
        }
    }
    @RequestMapping("/delById")
    public JsonResult delById(Long id){
        Boolean rs=lunboService.removeById(id);
        if(rs){
            return new JsonResult(200,"删除成功");
        }
        else{
            return new JsonResult(500,"删除失败");
        }
    }
    @RequestMapping("/list")
    public JsonResult list(@RequestBody Lunbo obj){
        List<Lunbo> list=lunboService.lists(obj);
        return new JsonResult(200,"查询成功",list);
    }
    @RequestMapping("/page/{curPage}/{pageRecords}")
    public JsonResult page(@RequestBody Lunbo obj,
                           @PathVariable int curPage,
                           @PathVariable int pageRecords){
        IPage<Lunbo> ipage=new Page<>(curPage,pageRecords);
        IPage<Lunbo> page=lunboService.pages(ipage,obj);
        return new JsonResult(200,"查询分页成功",page);
    }
}
